<html>
<head>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style>
        form {
            height: 180px;
            padding: 80px 60px 0px 10px;
            line-height: 22px;
            background-color: #393D49;
            color: #fff;
            ]font-weight: 300;
        }
    </style>
</head>
<body>
<form class="layui-form" action="login.action" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" id="password" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="login" lay-filter="demo1">提交</button>
            <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
        </div>
    </div>
</form>
<script type="text/javascript" src="layui/layui.all.js"></script>
<script>
    layui.use(['form', 'layer','laydate', 'jquery'], function (form, layer,laydate, $) {
        var index = parent.layer.getFrameIndex(window.name);
        $("#login").click(function () {
            $name = $("#username").val();
            $pass = $("#password").val();
            $.post('login.action', {username:$name,password:$pass}, function(str) {
                if(str == "true"){
                    layer.msg('登录成功', {
                        icon: 1,//提示的样式
                        time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                        end:function(){
                            parent.location.href='toindex.action';
                        }
                    });
                } else {
                    layer.msg('账号或密码错误！', {
                        icon: 0,//提示的样式
                        time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                    });
                }
            });
        })
    });
</script>
</body>
</html>
